<?php
/* @var $this EmailTemplatesController */
/* @var $model EmailTemplates */
/* @var $form CActiveForm */

//模板变量
$templateVar = EmailTemplates::model()->getVarUbb();
cs()->registerCoreScript('jquery'); 
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'email-templates-form',
	'enableAjaxValidation'=>false,
)); ?>
	<?php echo $form->errorSummary($model); ?>
	<?php echo $form->hiddenField($model,'inputtime'); ?>
	<?php echo $form->hiddenField($model,'zda_id'); ?>
	<ul class="form_list form_list2 mt10">
		<li class="title"><span class="fs_14 fw_b">创建/编辑模板</span></li>
		<li class="c_f"><span class="tit">模板名称：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zee_title',array('size'=>60,'maxlength'=>100,'class'=>'t_ipt w_300')); ?>
				<?php echo $form->error($model,'zee_title'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit">文件名称：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zee_filename',array('size'=>60,'maxlength'=>100,'class'=>'t_ipt w_300','readonly'=>!$model->isNewRecord)); ?>
				<?php echo $form->error($model,'zee_filename'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit">模板描述：</span>
			<div class="cont f_l">
				<?php echo $form->textArea($model,'zee_desc',array('cols'=>100,'rows'=>5)); ?>
				<?php echo $form->error($model,'zee_desc'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit">模板内容：</span>
			<div class="cont f_l">
				<?php //echo $form->textArea($model,'zee_content',array('cols'=>100,'rows'=>10,'id'=>'zee_content'))?>
				<?php  $this->widget('ext.keditor.KEditor',array(
		            'model'=>$model,  //传入form model
		            'name'=>'zee_content', //设置name
					'id'=>'zee_content',
		            'properties'=>array(
		                //设置接收文件上传的action
		                'uploadJson'=>'/Attachment/GetAjax',
		                //设置浏览服务器文件的action，这两个就是上面配置在/admin/default的
		             //   'fileManagerJson'=>'/Attachment/GetAjax',
		                'newlineTag'=>'br',
		                'allowFileManager'=>true,
		                //传值前加js:来标记这些是js代码
		                'afterCreate'=>"js:function() {
		                        K('#ChapterForm_all_len').val(this.count());
		                        K('#ChapterForm_word_len').val(this.count('text'));
		                    }",
		                'afterChange'=>"js:function() {
		                        K('#ChapterForm_all_len').val(this.count());
		                        K('#ChapterForm_word_len').val(this.count('text'));
		                    }",
		            ),
		            'textareaOptions'=>array(
		                'style'=>'width:700px;height:261px;',
		            )
		        )); ?>
				<?php echo $form->error($model,'zee_content'); ?>
			</div>
		</li> 
		<li class="c_f"><span class="tit">模板变量：</span>
			<div class="cont f_l">
				<?php foreach($templateVar as $key=>$val){?>
					<span class="template_var" val="<?php echo $val?>"> <?php echo $key?> </span>
				<?php }?>
			</div>
		</li> 
		<li class="c_f"><span class="tit">&nbsp;</span>
			<div class="cont f_l">
				<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('glo','Create') : Yii::t('glo','Save'),array('class'=>'mem_btn mem_btn20 mr5')); ?>
			</div>
		</li>
	</ul>	
<?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">
$('.template_var').bind('click',function(){
	var str = $(this).attr('val');
	editor_EmailTemplates_zee_content.insertHtml(str);//editor_EmailTemplates_zee_content js编辑器对象名称
});
</script>